package com.ethink.platform.job;

import cn.hutool.core.collection.CollUtil;
import com.ethink.order.api.TocSaleImportJobLogFacade;
import com.ethink.order.api.TocSaleImportLogFacade;
import com.ethink.order.api.response.TocSaleImportLogQueryDetailResponse;
import com.ethink.platform.manager.SaleOrderManager;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author default
 * @version 1.0.0
 * @ClassName TocSaleImportJob.java
 * @Description
 * @createTime 2022年12月20日 13:31:00
 */
@Component
@Slf4j
public class TocSaleImportJob {

    @Autowired
    private TocSaleImportLogFacade tocSaleImportLogFacade;

    @Autowired
    private TocSaleImportJobLogFacade tocSaleImportJobLogFacade;

    @Autowired
    private SaleOrderManager saleOrderManager;

    @XxlJob("TocSaleImportJob")
    public void tocSaleImport() {
        //查询未处理的日志
        List<Long> ids = tocSaleImportLogFacade.selectNotProcessed();
        if (CollUtil.isEmpty(ids)) {
            return;
        }
        for (Long id : ids) {
            TocSaleImportLogQueryDetailResponse response = tocSaleImportLogFacade.queryDetail(id);
            saleOrderManager.saleAdd2(response.getMain(), response.getItem());
        }
        return;
    }

}